﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TKToXML.Models
{
    public class HopDongChiTiet : BaseChungTu
    {
        
        //public virtual int SoChungTu { get; set; }
        public virtual int SoThuTu { get; set; }

        public virtual string MaHS { get; set; }
        public virtual string MaHangHoa { get; set; }
        public virtual string TenHangHoa { get; set; }
        public virtual string MaNuocXuatXu { get; set; }
        public virtual string MaDonViTinh { get; set; }
        public virtual decimal SoLuong { get; set; }
        public virtual string MaNguyenTe { get; set; }
        public virtual decimal DonGiaNguyenTe { get; set; }
        public virtual decimal TriGiaNguyenTe { get; set; }

        public virtual HopDong HopDong { get; set; }
        
        public virtual string ToXML()
        { 
            string result = "";            
            result += "<ContractItem>";
                result += "<unitPrice>" + DonGiaNguyenTe.ToString() + "</unitPrice>";
                result += "<statisticalValue>" + TriGiaNguyenTe.ToString() + "</statisticalValue>";
                result += "<Commodity>";
                    result += "<description>" + TenHangHoa + "</description>";
                    result += "<identification>" + MaHangHoa + "</identification>";
                    result += "<tariffClassification>" + MaHS + "</tariffClassification>";
                result += "</Commodity>";
                result += "<Origin>";
                    result += "<originCountry>" + MaNuocXuatXu + "</originCountry>";
                result += "</Origin>";
                result += "<GoodsMeasure>";
                    result += "<quantity>" + SoLuong.ToString() + "</quantity>";
                    result += "<measureUnit>" + MaDonViTinh + "</measureUnit>";
                result += "</GoodsMeasure>";
            result += "</ContractItem>";                
            return result;
        }

        public virtual bool Equals(HopDongChiTiet other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.NamChungTu == NamChungTu && other.SoChungTu.Equals(SoChungTu) && Equals(other.SoThuTu, SoThuTu);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(HopDongChiTiet)) return false;
            return Equals((HopDongChiTiet)obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
            //unchecked
            //{
            //    int result = Id;
            //    result = (result * 397) ^ Color.GetHashCode();
            //    result = (result * 397) ^ (Name != null ? Name.GetHashCode() : 0);
            //    return result;
            //}
        }

    }
}
